﻿        var res = "";
        $(document).ready(function () {
            var date = Date();
            $(".datepicker").datepicker({
                autoClose: true,
                startDate: date,
                format: 'dd/mm/yyyy'
            });
        });
        $('.formValidation').click(function () {
            var isError = "false";
            //check product name avilibility

            if (res == "true") {
                $('.productName').closest("#divProductName").addClass("error");
                isError = true;
            }
            else {
                $('.productName').closest("#divProductName").removeClass("error");
            }

            //category
            if ($('.category').val() == "" || $('.category').val() == "0") {
                $('.category').closest("#divCategory").addClass("error");
                isError = "true"
            }
            else
                $('.category').closest("#divCategory").removeClass("error");

            //brand
            if ($('.brandName').val() == "" || $('.brandName').val() == "0") {

                $('.brandName').closest("#divBrandName").addClass("error");
                isError = "true"
            }
            else
                $('.brandName').closest("#divBrandName").removeClass("error");


            //network
            if ($('.network').val() == "" || $('.network').val() == "0") {
                $('.network').closest("#divNetwork").addClass("error");
                isError = "true"
            }
            else
                $('.network').closest("#divNetwork").removeClass("error");

            //Product Name

            if ($('.productName').val() == "") {

                $('.productName').closest("#divProductName").addClass("error");
                isError = "true";
            }
            else
                $('.productName').closest("#divProductName").removeClass("error");
            //color
            if ($('.color').val() == "" || $('.color').val() == "0") {
                $('.color').closest("#divColor").addClass("error");
                isError = "true"
            }
            else
                $('.color').closest("#divColor").removeClass("error");


            //os
            if ($('.os').val() == "" || $('.os').val() == "0") {
                $('.os').closest('#divOs').addClass("error");
                isError = "true";
            }
            else
                $('.os').closest("#divOs").removeClass("error");

            //Rear Camera
            if ($('.rearCamera').val() == "") {

                $('.rearCamera').closest("#divRearCamera").addClass("error");
                isError = "true";
            }
            else {
                var data = $('.rearCamera').val();
                var r = checkNumeric(data);

                if (r == false) {

                    $('.rearCamera').closest("#divRearCamera").addClass("error");
                    isError = "true";
                }
                else {
                    $('.rearCamera').closest("#divRearCamera").removeClass("error");
                }
            }

            //internal memory
            if ($('.internalMemory').val() == "" || $('.internalMemory').val() == "0") {
                $('.internalMemory').closest('#divInternalMemory').addClass("error");
                isError = "true";
            }
            else
                $('.internalMemory').closest("#divInternalMemory").removeClass("error");


            //Display
            if ($('.display').val() == "") {

                $('.display').closest("#divDisplay").addClass("error");
                isError = "true";
            }
            else {
                var data = $('.display').val();
                var r = checkNumeric(data);

                if (r == false) {

                    $('.display').closest("#divDisplay").addClass("error");
                    isError = "true";
                }
                else {
                    $('.display').closest("#divDisplay").removeClass("error");
                }
            }

            //Sim Type
            if ($('.simType').val() == "" || $('.simType').val() == "0") {
                $('.simType').closest('#divSimType').addClass("error");
                isError = "true";
            }
            else
                $('.simType').closest("#divSimType").removeClass("error");

            //Form Factor
            if ($('.formFactor').val() == "" || $('.formFactor').val() == "0") {
                $('.formFactor').closest('#divFormFactor').addClass("error");
                isError = "true";
            }
            else
                $('.formFactor').closest("#divFormFactor").removeClass("error");


            //Form Factor
            if ($('.inputMethod').val() == "" || $('.inputMethod').val() == "0") {
                $('.inputMethod').closest('#divInputMethod').addClass("error");
                isError = "true";
            }
            else
                $('.inputMethod').closest("#divInputMethod").removeClass("error");
         

            if (isError == "true") {
                $('.generalMessage').html("<strong>Error! <strong/>Please Check your validation in red..");
                $('.generalMessage').addClass("alert alert-danger");
                setTimeout("window.scrollTo(0, 0)", 0);
                return false;
            }

        });
        function allowPositiveNo(evt) {

            var charCode = (evt.which) ? evt.which : event.keyCode

            if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
                return false;
            return true;
        }
        function checkNumeric(data) {
           
            var len = data.length;
            var c;
            var isNumeric = true;
            for (var i = 0; i < len; i++) {
                charCode = data.charAt(i).charCodeAt(0);
             
                if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
                    isNumeric = false;
                    break;
                }
                else {
                  
                }
            }
            return isNumeric; 
        }

        function checkProductnameAvailibility() {

            $.ajax({
                type: "POST",
                url: "./Add-Product.aspx/checkProductnameAvailibility",
                data: '{productname:"' + $('.productName').val() + '", Id: "' + $('.productId').text() + '"}',
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (response) {

                    res = response.d;
                    if (response.d == "true") {

                        $('.msg').html("<strong>ProductName is already exits.</strong>");
                        $('.msg').css("color", "#b94a48");
                        $('.productName').closest("#divProductName").addClass("error");

                    }
                    else {
                        $('.msg').html("");
                        $('.productName').closest("#divProductName").removeClass("error");

                    }


                },
                failure: function (response) {
                    alert(response.d);
                }

            });

            return res;
        }
